package com.cf.core.model.diagram.background.axis {
	import flash.display.Sprite;
	import com.cf.core.view.MyText;
	import com.cf.core.Utils.Rotator;
	import flash.geom.Point;
	public class Label extends Sprite{
		private var G_TMB:int;	// 0 Top, 1 Middle, 2 Bottom
		private var G_LCR:int;	// 0 Left, 1 Center, 2 Right
		private var G_rotator:Rotator;
		private var G_txt:MyText;
		public function set TOP(_t:Boolean):void { if (_t) G_TMB = 0; setPoint(); }
		public function set MIDDLE(_t:Boolean):void { if (_t) G_TMB = 1; setPoint();}
		public function set BOTTOM(_t:Boolean):void { if (_t) G_TMB = 2; setPoint();}
		public function set LEFT(_t:Boolean):void { if (_t) G_LCR = 0; setPoint();}
		public function set CENTER(_t:Boolean):void { if (_t) G_LCR = 1; setPoint();}
		public function set RIGHT(_t:Boolean):void { if (_t) G_LCR = 2; setPoint();}
		
		public function set txt(_o:MyText):void { G_txt = _o }
		public function get txt():MyText{return G_txt}
		
		// BUG : Remember to embedfont before roll, or it will disapper
		public function set roll(_n:Number):void {
			this.rotation = _n;
		}//fn
		public function get roll():Number {return G_rotator.rotation;}//fn
		
		
		/**
		// usage for test.
			var _label:Label = new Label();
			with (_label.txt) {
				txt.embedfont("Arial");
				txt.size = 18;
				txt.text = "Hello";
				x = 100 - _label.textWidth;
				y = 100 - _label.textHeight;
				BOTTOM = true;
				RIGHT = true;
				roll = 30;
				trace("Label at x:"+ _label.x +" y:"+_label.y+" roll:"+ _label.rotation +" embedFonts:"+ _label.embedFonts);
			}//with
			addChild(_label);
		*/
		public function Label():void {
			G_TMB = 0;
			G_LCR = 0;
			G_txt = new MyText();
			addChild(G_txt);
			G_rotator = new Rotator(G_txt);
		}//fn
		
		/**
		 * Use this.TOP/MIDDLE/BOTTOM/LEFT/CENTER/RIGHT to define this
		 * object's rotation point.
		 */
		private function setPoint():void {
			var _x:Number, _y:Number;
			switch(G_TMB) {
				default:
				case 0:	G_txt.y = G_txt.y; 					break;
				case 1:	G_txt.y = 0 - G_txt.height / 2;		break;
				case 2:	G_txt.y = 0 - G_txt.height;			break;
			}//case
			switch(G_LCR) {
				default:
				case 0: G_txt.x = G_txt.x;					break;
				case 1: G_txt.x = 0 - G_txt.width / 2;		break;
				case 2: G_txt.x = 0 - G_txt.width;			break;
			}//case
		}//fn
	}//clsas
}//package